package c.x.jy.wexin.controller;

import c.x.jy.common.utils.QrCodeUtil;
import c.x.jy.service.config.BusinessConfigService;
import c.x.jy.service.service.MemberService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import c.x.jy.common.utils.R;
import c.x.jy.dao.entity.MemberEntity;
import c.x.jy.service.comm.CommonService;

import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("wechat/comm")
public class CommController {

	@Autowired
	private CommonService commonService;
	@Autowired
	private Environment env;

	@Autowired
	private BusinessConfigService businessConfigService;
	
    @Autowired
    private MemberService memberService;

	@RequestMapping("/areaList")
	public R areaList() {

		return R.ok().put("data", commonService.areaList());

	}

	@RequestMapping("/vipprice")
	public R vipprice() {

		String price = businessConfigService.getBusinessConfigValue(null, "VIP_CERT_PRICE");
		return R.put(price);

	}

	@RequestMapping("/qrCode")
	public void qrCode(String bcode, String mcode, HttpServletResponse response) {
		// AESUtil.AESEncode(code, env.getProperty("smartlock.secret"))
	//	System.out.println("base url=" + env.getProperty("xuanzhu.baseUrl"));
		QrCodeUtil.getQrCode(env.getProperty("xuanzhu.baseUrl")
				+ (env.getProperty("xuanzhu.wechatUrl") == null ? "" : env.getProperty("xuanzhu.wechatUrl"))
				+ "wechat/tologin?bcode=" + bcode + "&mcode=" + mcode, response);
	}

//	@RequestMapping("/remove")
//	public R removeCache(Long id) {
//
// 
//		memberService.removeMemberCache(memberService.getById(id));
//		return R.ok() ;
//
//	}

}
